﻿using Microsoft.EntityFrameworkCore;

namespace MyEFCore
{
    public class MyDbContext : DbContext
    {
        public DbSet<Product> Products { get; set; }

        public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
        {
        }


        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Product>().Property(p => p.Name).IsRequired().HasMaxLength(50);
            modelBuilder.Entity<Product>().Property(p => p.Category).IsRequired().HasMaxLength(20);

            modelBuilder.Entity<Product>().HasData
            (
                new Product { ProductId = 1, Name = "Ball", Category = "Sports" },
                new Product { ProductId = 2, Name = "Blanket", Category = "Accessories" },
                new Product { ProductId = 3, Name = "Bicycle", Category = "Vehicle" }
            );
        }
    }
}
